package com.cybertron.ironhide.manage.common.base;

import org.apache.ibatis.session.RowBounds;

public class Pager extends RowBounds {

	public static final Integer MAX_PAGE_SIZE = 1000;// 每页最大记录数限制

	private Integer pageNum = 1;// 当前页码

	private Integer numPerPage = 20;// 每页记录数

	private Integer pageCount = new Integer(0);// 总页数

	private Long totalCount = new Long(0);// 总记录数

	private String orderField = "";// 排序字段

	private String orderDirection = "asc";// 排序方式

	public Pager() {
		super();
	}

	public Pager(Integer pageNum) {
		this(pageNum, 20);
	}

	public Pager(Integer pageNum, Integer numPerPage) {
		super();
		if (pageNum < 1) {
			pageNum = 1;
		}
		if (numPerPage < 1) {
			numPerPage = 1;
		} else if (numPerPage > MAX_PAGE_SIZE) {
			numPerPage = MAX_PAGE_SIZE;
		}
		this.pageNum = pageNum;
		this.numPerPage = numPerPage;
	}

	public void setPageNum(Integer pageNum) {
		this.pageNum = pageNum;
	}

	public void setNumPerPage(Integer numPerPage) {
		this.numPerPage = numPerPage;
	}

	public Integer getPageNum() {
		return pageNum;
	}

	public Integer getNumPerPage() {
		return numPerPage;
	}

	public String getOrderField() {
		return orderField;
	}

	public void setOrderField(String orderField) {
		this.orderField = orderField;
	}

	public String getOrderDirection() {
		return orderDirection;
	}

	public void setOrderDirection(String orderDirection) {
		this.orderDirection = orderDirection;
	}

	public Integer getPageCount() {
		pageCount = totalCount.intValue() / numPerPage;
		if (totalCount.intValue() % numPerPage > 0) {
			pageCount++;
		}
		return pageCount;
	}

	public void setPageCount(Integer pageCount) {
		this.pageCount = pageCount;
	}

	public Long getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(Long totalCount) {
		this.totalCount = totalCount;
	}

}